﻿using System;
using System.Collections.Generic;
using System.Text;

using WorldMap = System.Collections.Generic.Dictionary<int, PosWorld>;

/**
*@file       worldcore.cs
*@brief      manage all world
*
*@author     graywind
*@version    1.0.0.1
*@data       2012/03/07
*/

public class WorldCore
{
    #region private variable
    //pos world
    private WorldMap m_mapWorld = new WorldMap();
    #endregion

    #region event
    #endregion

    #region external call
    /// <summary>
    /// add instance
    /// </summary>
    /// <param name="pos_world"></param>
    /// <returns></returns>
    public bool Add(PosWorld pos_world)
    {
        lock (m_mapWorld)
        {
            if (!m_mapWorld.ContainsKey(pos_world.WorldId))
            {
                m_mapWorld.Add(pos_world.WorldId, pos_world);
                return true;
            }
        }

        return false;
    }

    /// <summary>
    /// remove a instance
    /// </summary>
    /// <param name="world_id"></param>
    public void Remove(int world_id)
    {
        lock (m_mapWorld)
        {
            if (m_mapWorld.ContainsKey(world_id))
                m_mapWorld.Remove(world_id);
        }
    }

    /// <summary>
    /// get a instance
    /// </summary>
    /// <param name="world_id"></param>
    public PosWorld Get(int world_id)
    {
        lock (m_mapWorld)
        {
            PosWorld ps;
            if (m_mapWorld.TryGetValue(world_id, out ps))
                return ps;
        }

        return null;
    }
    #endregion
}